home *** CD-ROM | disk | FTP | other *** search
- (*
- ' *************************************************************************
- ' * Scriptname: Open Versions With
- ' * Author: HB van Zwietering
- ' * Version: 1.0
- ' * Date: 15-December-2006
- ' *
- ' * Description: The script allows to select one or more versions from one or more selected
- ' * version stacks and then allows to open the selected images in an external application
- ' *
- ' * Known Issues:
- ' * -
- ' *************************************************************************/
- *)
-
-
- function AddFileName (AList: TStringList; AFileName: String): Integer;
- begin
- result := AList.IndexOf (AFileName);
-
- if result = -1 then // doesn't exist yet?
- result := AList.Add (AFileName);
- end;
-
- function AskApp (AApps, AList: TStringList; var AParams: String): String;
- var
- AForm: TForm;
- APanel: TPanel;
- AOk: TButton;
- ARg: TRadioGroup;
- ALb: TListBox;
- i: Integer;
- ARegKey: String;
- begin
- result := '';
- AParams := '';
-
- ARegKey := 'scripts\openversionwith\' + ExtractFileExt (AList.Strings[0]);
-
- AForm := TForm.Create(nil);
- AForm.Caption := 'Open Versions With...';
- AForm.Width := ReadFromRegistry ('scripts\openversionwith\', 'Width', 600);
- AForm.Height := ReadFromRegistry ('scripts\openversionwith\', 'Height', 400);
- AForm.Position := poScreenCenter;
-
- APanel := TPanel.Create (AForm);
- APanel.Parent := AForm;
- APanel.Align := alBottom;
- APanel.Height := 35;
-
- AOk := TButton.Create (AForm);
- AOk.Caption := 'Ok';
- AOk.ModalResult := mrOk;
- AOk.Parent := APanel;
- AOk.Top := 6;
- AOk.Left := 6;
-
- ALb := TListBox.Create (AForm);
- ALb.Parent := AForm;
- ALb.Align := alClient;
- for i := 0 to AList.Count - 1 do
- ALb.Items.Add (AList.Strings[i]);
- ALb.MultiSelect := True;
- ALb.SelectAll;
-
- ARg := TRadioGroup.Create (AForm);
- ARg.Parent := AForm;
- ARg.Caption := 'open with';
- //ARg.Items.AddStrings (AApps);
- for i := 0 to AApps.Count - 1 do
- ARg.Items.Add (ChangeFileExt (ExtractFileName (AApps.Strings[i]), ''));
- ARg.Height := 30 + (AApps.Count * (AForm.Canvas.TextHeight ('X') + 5));
- ARg.ItemIndex := ReadFromRegistry (ARegKey, 'LastApp', 0);
- if ARg.ItemIndex = -1 then
- ARg.ItemIndex := 0;
- ARg.Align := alBottom;
-
- ForceForegroundWindow (AForm.Handle);
-
- AForm.ShowModal;
-
- if AForm.ModalResult = mrOk then
- begin
- WriteToRegistry ('scripts\openversionwith\', 'Width', AForm.Width);
- WriteToRegistry ('scripts\openversionwith\', 'Height', AForm.Height);
- WriteToRegistry (ARegKey, 'LastApp', ARg.ItemIndex);
-
- result := AApps.Strings[ARg.ItemIndex];
-
- // return all the selected images
- for i := 0 to ALb.Items.Count - 1 do
- begin
- if ALb.Selected[i] then
- AParams := AParams + iif (AParams = '', '', ' ') + '"' + AList.Strings[i] + '"';
- end;
- end;
-
- AForm.Free;
- end;
-
- function DoOpenWith (AList: TStringList): Integer;
- var
- ATemp, CustomOpenWithPrograms: TStringList;
- AApp, AParams: String;
- ShellObj: OleVariant;
- i, j: Integer;
- begin
- // returns the result code from the calling application
- result := -1;
-
- CustomOpenWithPrograms := TStringList.Create;
- CustomOpenWithPrograms.CaseSensitive := False;
-
- // find the registered Open With programs for each file extension found and build a unique list of
- // applications from it
- ATemp := TStringList.Create;
- for i := 0 to AList.Count - 1 do
- begin
- ATemp.Clear;
- ATemp.Text := ReadFromRegistry('OpenWith', ExtractFileExt (AList.Strings[i]), '');
-
- for j := 0 to ATemp.Count - 1 do
- begin
- if CustomOpenWithPrograms.IndexOf (ATemp.Strings[j]) = -1 then
- CustomOpenWithPrograms.Add (ATemp.Strings[j]);
- end;
- end;
- ATemp.Free;
-
- if CustomOpenWithPrograms.Count > 0 then
- begin
- // now ask what program should be used to open the files with
- AApp := AskApp (CustomOpenWithPrograms, AList, AParams);
-
- if AApp <> '' then
- begin
- //Say ('"' + AApp + '" ' + AParams);
-
- // start the selected application through the shell
- ShellObj := CreateOleObject ('WScript.Shell');
- // WshShell.Run (strCommand, [intWindowStyle], [bWaitOnReturn])
- result := ShellObj.Run('"' + AApp + '" ' + AParams, 1, True);
- ShellObj := nil;
-
- //Say (result);
- end;
- end;
-
- CustomOpenWithPrograms.Free;
- end;
-
- var
- AFileList: TStringList;
- ACatItem: TCatalogItem;
- AVersions: TCatalogItems;
- i, j: Integer;
- begin
- AFileList := TStringList.Create;
- AFileList.CaseSensitive := False;
-
- ACatItem := TCatalogItem.Create (nil);
- AVersions := TCatalogItems.Create (TCatalogItem, '');
-
- for i := 0 to Selected.Count - 1 do
- begin
- // find each selected image in catalog, and if it is a version, then return the main version
- if Catalog.FindImageCombined (Selected.Items[i], ACatItem, True, phtNone) then
- begin
- AddFileName (AFileList, ACatItem.FileName);
-
- AVersions.Clear;
-
- Catalog.EnumVersionsForItem (ACatItem, AVersions);
-
- // populate all filenames to the file list, but check that they don't exist already (f.i. when two thumbs are selected from the same stack)
- for j := 0 to AVersions.Count - 1 do
- AddFileName (AFileList, AVersions.Items[j].FileName);
- end;
- end;
-
- AVersions.Free;
- ACatItem.Free;
-
- if AFileList.Count = 0 then // nothing added?? hmm, let's exit
- exit;
-
- // now we have a list of files that should be used as parameters for the external application to open
- DoOpenWith (AFileList);
-
- AFileList.Free;
- end;
-